package com.jackiechan.day13;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

public class Test2 {
    public static void main(String[] args) {
        Collection<Integer> c = new ArrayList();
        Collection<Integer> x = new ArrayList();
        c.add(456);
        c.add(123);
        c.add(789);
        c.add(123);
        c.add(456);
        c.add(789);
        x.add(123);
        x.add(456);
//        System.out.println(c.add("23"));
        System.out.println(c);
        // 是否包含
        System.out.println(c.contains(123));
        // 是否相等
        System.out.println(c.equals(x));
        // 哈希码
        System.out.println(c.hashCode());
        // 清除
//        c.clear();
//        System.out.println(c);
        // 是否为空
        System.out.println(c.isEmpty());
        // 移除
        System.out.println(x.remove(123));
        System.out.println(x);
        // 集合长度
        System.out.println(x.size());
        // 转换成数组
        System.out.println(x.toArray());
        System.out.println(String.valueOf(Arrays.toString(x.toArray())));

        Collection y = new ArrayList();
        y.add(456);
        y.add(789);
        // 是否包含
        System.out.println(y);
        System.out.println(c.containsAll(y));
        // 添加集合中所有元素
        c.addAll(y);
        System.out.println(c);
        // 移除交集
//        c.removeAll(y);
//        System.out.println(c);
        // 保留交集
        c.retainAll(y);
        System.out.println(c);

        Collection<Integer> z = new ArrayList();
        z.addAll(c);
        // 返回可以迭代集合元素的迭代器
        System.out.println(z.iterator());
        Iterator<Integer> it = z.iterator();
        while (it.hasNext()){
            System.out.print(it.next()+" ");
//            it.remove();
        }
        System.out.println();
        System.out.println(z);

        for (Integer i:z){
            System.out.print(i+" ");
        }
        System.out.println();
    }
}
